#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION                                                   #
#######################################################################
cat > prop_exci_morpa_trip.info <<'%EOF%'
   prop_exci_morpa_trip
   --------------------
   Molecule:         Water
   Wave Function:    SCF/RPA with STO2G
   Test Purpose:     Triplet excitation energies at RPA level
                     calculated with the standard ABACUS code
%EOF%

#######################################################################
#  MOLECULE INPUT                                                     #
#######################################################################
cat > prop_exci_morpa_trip.mol <<'%EOF%'
BASIS
STO-2G
Calculation of excitation energies through ABACUS

Atomtypes=2 Multiplicity=1 Charge=0 Generators=2  X  Y
Charge=8.0 Atoms=1
O   0.00000             0.00000              0.1241444240
Charge=1.0 Atoms=1
H   0.00000             1.43153              -0.985265576
FINISH
%EOF%

#######################################################################
#  DALTON INPUT                                                       #
#######################################################################
cat > prop_exci_morpa_trip.dal <<'%EOF%'
**DALTON INPUT
.RUN PROPERTIES
**WAVE FUNCTIONS
.HF
*SCF INPUT
.THRESH
 1.0D-10
**PROPERTIES
.EXCITA
*EXCITA
.TRIPLE
.NEXCITA
    4    1    4    0
*END OF INPUT

%EOF%

#######################################################################
#  CHECK SCRIPT                                                       #
#######################################################################
echo $CHECK_SHELL > prop_exci_morpa_trip.check
cat >> prop_exci_morpa_trip.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

# Ground state energies
CRIT1=`$GREP "Final HF energy\: * \-72\.73901238[0-9][0-9][0-9][0-9]" $log | wc -l`
CRIT2=`$GREP "Nuclear repulsion\: * 9\.18370623[0-9][0-9][0-9][0-9]" $log | wc -l`
CRIT3=`$GREP "Electronic energy\: * \-81\.92271861[0-9][0-9][0-9][0-9]" $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[1]=3
ERROR[1]="GROUND STATE ENERGIES NOT CORRECT"

# Excited triplet state energies
CRIT1=`$GREP "1 * 1 * (0| )\.4834[0-9][0-9]" $log | wc -l`
CRIT2=`$GREP "1 * 2 * (0| )\.7602[0-9][0-9]" $log | wc -l`
CRIT3=`$GREP "1 * 3 * 1\.2861[0-9][0-9]" $log | wc -l`
CRIT4=`$GREP "1 * 4 * 19\.4256[0-9][0-9]" $log | wc -l`
CRIT5=`$GREP "2 * 1 * (0| )\.4020[0-9][0-9]" $log | wc -l`
CRIT6=`$GREP "3 * 1 * (0| )\.5577[0-9][0-9]" $log | wc -l`
CRIT7=`$GREP "3 * 2 * (0| )\.6819[0-9][0-9]" $log | wc -l`
CRIT8=`$GREP "3 * 3 * 1\.4137[0-9][0-9]" $log | wc -l`
CRIT9=`$GREP "3 * 4 * 19\.5146[0-9][0-9]" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9`
CTRL[2]=9
ERROR[2]="EXCITED TRIPLET STATE ENERGIES NOT CORRECT"

PASSED=1
for i in 1 2
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
      echo ${ERROR[i]}
      PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
   echo TEST ENDED PROPERLY
   exit 0
else
   echo THERE IS A PROBLEM
   exit 1
fi

%EOF%
